<template>
  <li id="todo" class="tab-pane tab-item">
    <div class="list-header">待办设置</div>
    <label class="title-sm">选择要接收的待办类型：</label>
    <ul>
      <div class="col-md-6 css-db-01">
        <template v-if="lis !== ''" v-for="(f,k) in lis" >
          <p v-if="f.checked" class='choose-checkbox' :key="k"><span class='check-span checked'><input checked='checked'  type='checkbox' :mestype='f.name'  :name='f.boxLabel' :value='f.name + "@" + f.inputValue'/></span>{{f.boxLabel}}</p>
          <p v-else class='choose-checkbox' :key="k"><span class='check-span'><input type='checkbox' :mestype='f.name'  :name='f.boxLabel' :value='f.name + "@" + f.inputValue'/></span>{{f.boxLabel}}</p>
        </template>
      </div>
      <div class="col-md-6 css-db-02">
        <template v-if="lissecond !== ''" v-for="(f,k) in lissecond" >
          <p v-if="f.checked" class='choose-checkbox' :key="k"><span class='check-span checked'><input checked='checked'  type='checkbox' :mestype='f.name'  :name='f.boxLabel' :value='f.name + "@" + f.inputValue'/></span>{{f.boxLabel}}</p>
          <p v-else class='choose-checkbox' :key="k"><span class='check-span'><input type='checkbox' :mestype='f.name'  :name='f.boxLabel' :value='f.name + "@" + f.inputValue'/></span>{{f.boxLabel}}</p>
        </template>
      </div>
    </ul>

    <div class="tools">
      <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
      <button type="button" class="btn btn-primary" @click="submitcssdb()">确定</button>
    </div>
  </li>
</template>

<script>
    export default {
      name: "todo",
      data(){
        return {
          lissecond:'',
          lis:''
        }
      },
      methods:{
        initdata(k){
          this.axios.post(MESSAGE_SERVICE_URL + "perMesCheckboxController/queryCheckboxByEmpCode",{
            key: k
          }).then((data)=>{
            let res = data.data;
            if(res.length > 0){
              this.lissecond = [];
              this.lis = [];
              for(let i = 0;i < res.length;++i){
                if (i % 2 !== 0) {
                  this.lissecond.push(res[i]);
                } else {
                  this.lis.push(res[i]);
                }
              }
            }else{
              this.lissecond = '';
              this.lis = '';
            }
          }).catch(()=>{
            console.log("动态加载复选框未知异常！");
          })
        },
        submitcssdb() {
          let updatedate = "";
          let doms = document.querySelectorAll(".css-db-01 input,.css-db-02 input");
          for(let i = 0;i < doms.length;++i){
            if (doms[i].checked === true) {
              updatedate += doms[i].value + "@" + doms[i].name;
              updatedate += ":";
            }
          }
          updatedate = updatedate.substring(0, updatedate.length - 1);
          this.axios.post(
            MESSAGE_SERVICE_URL + "perMesTypeController/submitCheckbox?type=2",
            {key: updatedate}).then((res)=>{
            let r = res.data;

            if('SUCCESS'===r.status){
              console.log('sssssssssssssssssssssssssssssssss');
              console.log(showMsg);
              showMsg('success', r.body);
            }else{
              showMsg('warn', r.body);
            }
          }).catch(()=>{
            showMsg('warn', "提交未知异常");
          })
        }
      },
      created(){
        this.initdata('1');
      }
    }
</script>

<style scoped>

</style>
